package com.kathir.database.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.ResultSetMetaData;

public class Display {	
	public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
		while(true){
			System.out.println("Enter the Query");
			BufferedReader brObj= new BufferedReader(new InputStreamReader(System.in));
			Class.forName("com.mysql.jdbc.Driver");
			Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
			Statement statement = connect.createStatement();
			String value = brObj.readLine();
			ResultSet rs = statement.executeQuery(value);
			ResultSetMetaData rsmd = (ResultSetMetaData) rs.getMetaData();
			while(rs.next()){
				for(int a= 1;a<=rsmd.getColumnCount();a++ )
				{
					System.out.print(rs.getString(a)+"\t");
				}
				System.out.println();
			
			while (rs.next()) {
				//ResultSetMetaData rsmd1 = null;
				//ResultSetMetaData metadata = null;
				String values[] = new String[rsmd.getColumnCount()];
				for (int i = 1; i < rsmd.getColumnCount(); i++) {
					String columnName = rsmd.getColumnName(i);
					System.out.println("Enter the details:"+columnName);
					BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
					values[i-1] = brObj1.readLine();
					
				}

			}
		}
	}
}
}
